import alpaca.exceptions as alpaca_ex

def patched_raise_alpaca_if(n, m):
    if n == 0:
        return
    if n == 0x0400:
        raise alpaca_ex.NotImplementedException(m)
    elif n == 0x0401:
        raise alpaca_ex.InvalidValueException(m)
    elif n == 0x0402:
        raise alpaca_ex.ValueNotSetException(m)
    elif n == 0x0407:
        raise alpaca_ex.NotConnectedException(m)
    elif n == 0x0408:
        raise alpaca_ex.ParkedException(m)
    elif n == 0x0409:
        raise alpaca_ex.SlavedException(m)
    elif n == 0x040B:
        raise alpaca_ex.InvalidOperationException(m)
    elif n == 0x040C:
        raise alpaca_ex.ActionNotImplementedException(m)
    elif 0x400 <= n <= 0xFFF:
        raise alpaca_ex.DriverException(n, m)
    else:
        raise alpaca_ex.DriverException(n, m)

# 👇 在 import 时立即生效
alpaca_ex.raise_alpaca_if = patched_raise_alpaca_if
